<?php
	class AdminLayoutController extends Zone_Action{
		public function fields(){
			$data = array(
				title => array(
					type => 'CHAR',
					form_label => 'Tiêu đề'
				),
				desc => array(
					type => 'CHAR',
					form_label => 'Sologan'
				)
			);
			return $data;	
		}
				
		
		public function indexAction(){
			
			if(isPost()){
				$this->removeLayout();
				loadClass('ZData');
				$f = new ZData();
				$f->addField($this->fields());
				$data = $f->getData();				
				if( !is_array( $data ) ){
					return $this->setJson(array(
						alert	=> $data
					));
				}
				if(!$this->Model->Update('configs',$data)){
					$this->Model->Insert('configs',$data);
				}
				return $this->setJson(array(
					callback => "(function(){ 
						window.location.reload();
					})()"
				));				
			}
			
			$configs = $this->Model->fetchRow("SELECT * FROM `configs` LIMIT 1");
			$this->set('configs',$configs);			
		}		
		
		public function logoAction(){
			$this->removeLayout();
			if( !isPost() ){
				return $this->setJSON(array(
					error	=> 'Truy cập không được chấp nhận'
				));
			}
			
			loadClass('ZData');
			$f = new ZData();
			$f->addField(array(
				logo	=> array(
					type			=>	'FILE',
					return_name		=>	true,
					path			=>	'files/configs',
					default_value	=>	'logo.png'
				)
			));
			
			$data = $f->getData();
			if( !is_array($data) ){
				return $this->setJSON(array(
					error	=>	$data
				));	
			}		
			
			return $this->setJSON(array(
					callback => "(function(){ 
						window.location.reload();
					})()"
				));
		}
		
		
		
	}
 ?>